﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace PS.ImageRotator.ImageRotatorWebPart
{
    [ToolboxItemAttribute(false)]
    public class ImageRotatorWebPart : WebPart
    {
        #region Fields

        private const string _jQueryToken = "__PSIMAGEROTATOR_JQUERY__";
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/PS.ImageRotator/ImageRotatorWebPart/ImageRotatorWebPartUserControl.ascx";
        private const string _jQueryPath = @"/_layouts/PS.ImageRotator/js/jquery.js";
        //private const string _bannerJS = @"/_layouts/js/frontpage.module.js";

        #endregion Fields
        #region Methods

        /// <summary>
        /// Called on load event.
        /// </summary>
        /// <param name="e">Event args.</param>
        protected override void OnLoad(EventArgs e)
        {
            // Call base version.
            base.OnLoad(e);
            // Load JQUERY references.
            if (null == Page) return;
            if (!Page.ClientScript.IsClientScriptIncludeRegistered(_jQueryToken))
                Page.ClientScript.RegisterClientScriptInclude(_jQueryToken, _jQueryPath);
        }
        protected override void CreateChildControls()
        {
            Control control = Page.LoadControl(_ascxPath);
            Controls.Add(control);
        }
        #endregion Methods
    }
}
